<?Lassoscript
// Last modified 11/30/09 by Eric Landmann

// FUNCTIONALITY
// Building Google links for search response pages
// Creates the HTML for five links, like this:
//  1  |  2  |  3  |  4  |  5  |  NEXT

// CHANGE NOTES
// 4/17/09
// Version 1.0
// 11/30/09
// Worked on admin area

// Putting the whole link into a string to be called wherever we want on the page.
Var:'NavControlLinks' = string;

// Define the Link Page
// NOTE: We are now ALWAYS passing $SID and $TID, to make this universal
// If we are on Topics, the link page goes to the Topics (topic.lasso)
// If we are on Thread, the link page goes to the Thread (thread.lasso)
// If we are on a Search or Search Response page, the link goes to searchresponse.lasso
If: (Response_Filepath) >> 'topic.lasso';
	Var:'LinkPage' = 'topic.lasso';
Else: (Response_Filepath) >> 'thread.lasso';
	Var:'LinkPage' = 'thread.lasso';
Else: (Response_Filepath) >> 'search.lasso' || (Response_Filepath) >> 'searchresponse.lasso';
	Var:'LinkPage' = 'searchresponse.lasso';
// Otherwise Response_filepath is screwy, send them to the home page
Else;
	Var:'LinkPage' = '/';
/If;

$NavControlLinks += ('<!-- START Nav Control -->\n');

// Display Found_Count
If: (Found_Count) > 0;
	$NavControlLinks += ('Displaying <strong>' (Shown_First) '</strong> through <strong>' (Shown_Last) '</strong> of <strong><font color="red">' (Found_Count) '</font></strong> records.<br>\n');
/If;

// PREV link
If: $This_Group > 0;
	$NavControlLinks += ('<a href="'($LinkPage)'?SID='(Var:'svSID')'&TID='(Var:'svTID')'&skip='(math_sub: (shown_first), $Group_Size, 1)'&group='(Math_Sub: $This_Group, 1)'"> PREVIOUS GROUP</a><span class="ghost">&nbsp;|&nbsp;</span>');

/If;

// MIDDLE links
$SkipCount = (Math_Mult:$This_Group,$Group_Size);
$Records_Found = (Found_Count);

If: $Records_Found > $Records_Per_Page;
	Loop: 5;
		If: $SkipCount >= $Records_Found;
			Loop_Abort;
		/If;
		$SkipCount = (Math_Add: $SkipCount, $Records_Per_Page);
		If: $Records_Skipped == (Math_Sub: $SkipCount, $Records_Per_Page);
			$NavControlLinks += ('<strong>' (Math_Div: $SkipCount, $Records_Per_Page) '</strong>\n');
		Else;
			$NavControlLinks += ('<a href="'($LinkPage)'?SID='(Var:'svSID')'&TID='(Var:'svTID')'&skip='(Math_Sub: $SkipCount, $Records_Per_Page)'&group='($This_Group)'">'(Math_Div: $SkipCount, $Records_Per_Page)'</a>');
		/If;
		If: ((Loop_Count) < 5) && ($SkipCount < $Records_Found);
			$NavControlLinks += ('<span class="ghost">&nbsp;|&nbsp;</span>');
		/If;
	/Loop;

// NEXT link
	If: (Found_Count) > $SkipCount;
		$This_Group = (Math_Add:$This_Group,1);
		$NavControlLinks += ('<span class="ghost">&nbsp;|&nbsp;</span><a href="'($LinkPage)'?SID='(Var:'svSID')'&TID='(Var:'svTID')'&skip='(math_mult: $Group_Size, $This_Group)'&group='($This_Group)'">NEXT GROUP</a>\n');
	/If;
/If;

$NavControlLinks += ('<!-- END Nav Control -->\n');
?>